﻿Namespace EIB.Bus.KNXNetIP
    Public Class KNXNetIP_FrameBase
        Inherits FrameBase

        Protected _Version As KNXNetIP_FrameVersion = Nothing
        Protected _Service As KNXNetIP_FrameService = Nothing
        Protected _Length As UInt16 = Nothing

        Protected _KNXNetIP_Data As Byte() = Nothing


        Sub New(busdata As Byte())
            If Not busdata(0) = 6 Then Throw New EIB.Exceptions.EIBDataDecodeException("")
            If Not busdata(1) = KNXNetIP_FrameVersion.Version10 Then Throw New EIB.Exceptions.EIBDataDecodeException("")

            'Header
            Dim headerLength As Byte = busdata(0) '=6
            _Version = busdata(1)
            _Service = (busdata(2) << 8) + busdata(3)
            _Length = (busdata(4) << 8) + busdata(5)


        End Sub

        Sub New(version As KNXNetIP_FrameVersion, service As KNXNetIP_FrameService)
            If Not [Enum].IsDefined(GetType(KNXNetIP_FrameVersion), version) Then Throw New EIB.Exceptions.EIBDataEncodeException("")
            If version <> KNXNetIP_FrameVersion.Version10 Then Throw New EIB.Exceptions.EIBDataEncodeException("")
            If Not [Enum].IsDefined(GetType(KNXNetIP_FrameService), service) Then Throw New EIB.Exceptions.EIBDataEncodeException("")

            _Version = version
            _Service = service
        End Sub


        Public ReadOnly Property BusData As Byte()
            Get
                Return _KNXNetIP_Data
            End Get
        End Property

        Public ReadOnly Property Version As KNXNetIP_FrameVersion
            Get
                Return _Version
            End Get
        End Property


        Public Overrides Function ToInfoList() As System.Collections.Generic.List(Of EIB.InfoBase)

        End Function
    End Class
End Namespace